package com.guigu.eduservice.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guigu.eduservice.entity.Advertisement;
import com.guigu.eduservice.service.AdvertisementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 广告表（管理PC端和小程序端的广告展示） 前端控制器
 * </p>
 *
 * @author janecraft
 * @since 2025-09-27
 */
@RestController
@RequestMapping("/eduservice/advertisement")
public class AdvertisementController {

    @Autowired
    private AdvertisementService advertisementService;

    //获取所有广告,0-小程序轮播广告，1-PC端广告
    @GetMapping("/getAll/{adtype}")
    public List<Advertisement> getAll(@PathVariable("adtype") int adtype) {
        QueryWrapper<Advertisement> wrapper = new QueryWrapper<>();
        wrapper.eq("ad_type", adtype);
        wrapper.eq("status", 1);//启用,0为禁用
        wrapper.orderByDesc("sort");//根据sort属性，从大到小排序
        return advertisementService.list(wrapper);
    }
}
